//
//  KDLibrary.h
//  Source List
//
//  Created by Keith Duncan on 05/03/2008.
//  Copyright 2008 thirty-three. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@class AFLibrary, AFSourceNode;

extern NSString *const AFLibraryUnknownLocation;

NS_INLINE BOOL AFFileExistsAtPath(NSString *path) {
	return (path != nil && ![path isEmpty] && [[NSFileManager defaultManager] fileExistsAtPath:[path stringByExpandingTildeInPath]]);
}

// This is used for converting KDLibrary subclasses to NSMenu
@protocol AFLibraryDelegate <NSObject, AFBundleDiscovery>
- (void)requestPathForLibrary:(AFLibrary *)library;
@optional
// Root children are NEVER selectable and you won't be queried
- (BOOL)library:(AFLibrary *)library isObjectSelectable:(id)object;
@end

/*!
    @class
    @abstract    This is an abstract class for loading XML library representations, iTunes initially, perhaps iPhoto or another custom store
*/

@interface AFLibrary : NSObject {
	id <AFLibraryDelegate> delegate;
	
	BOOL _loaded;
	
	id _library;
	NSString *_path;
	
	AFSourceNode *_rootNode;
}

// init with KDLibraryUnknownLocation to trigger an immediate request
- (id)initWithFilePath:(NSString *)path;

@property (copy) NSString *path;

@property (assign) id <AFLibraryDelegate> delegate;

- (BOOL)isLoaded;
- (BOOL)loadAndReturnError:(NSError **)error;

@property (retain, readonly) AFSourceNode *rootNode;

// This should really be a subclass specific function

- (NSMenu *)sourceMenu;

@end

// Subclasses must also conform to this protocol

@protocol AFLibraryDiscovery <NSObject>
- (NSString *)name;
- (NSString *)expectedPath;
@optional
- (NSArray *)additionalSearchPaths;
@end
